package chapter12_并发程序的测试.产生更多的交替操作;

import others.Account;

import java.util.Random;

public class AccountTransfer {
    int THRESHOLD = 400;

    public synchronized void transferCredits(Account from, Account to, double amout) {
        Random random = new Random();
        from.setBalance(from.getBalance() - amout);
        if (random.nextInt(1000) > THRESHOLD) {
            // 让出时间分片，产生更多交替
            Thread.yield();
        }
        to.setBalance(to.getBalance() + amout);
    }
}
